<?php
namespace app\home\controller;
use think\Db;
use think\captcha\Captcha;
use think\Loader;
class Diwu extends \think\Controller{
    public function diwu(){
        return $this->fetch('diwu');//继承基类的控制器 
    }
    public function fabu(){
        $data=input('param.','','htmlspecialchars');
        $data['title']=input('param.title','','htmlspecialchars');
        $data['author']=input('param.author','','htmlspecialchars');
        $data['topic']=input('param.topic','','htmlspecialchars');
        $data['content']=input('param.content','','htmlspecialchars');
        $data['time']=time();
        $data['img']=json_encode($data['img']); 
        $ret=db('article')->insert($data);
            if($ret>0){
                $this->success('发布成功!','home/diwu/diwu');
            }else{
                $this->error('发布失败');
            }
            
    }
    public function upload(){
        $file=request()->file('img');
            if($file){
                $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
                if($info){
                    $path=$info->getSaveName();
                    $img_src="/uploads/".$path;
                    echo $img_src;
                }else{
                    //	上传失败获取错误信息
                    $this->error($file->getError());
                }
            }
            else{
                $this->error("必须上传图片");
            }
    }

    
}